﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		pageAdvice = getProperty("serviceFactory").getBean("pageAdvice");

		teacherId = sessionAdvice.getAutherUserID();
		
		hashCode = event.getArg("Sign");
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");

		checked = false;
				
		if ( decrypt(hashCode, teacherId, "PBEWithMD5AndDES", "Hex") eq taskId ) {
			
			/* 载入补考教学任务 */
			
			sql = "SELECT 
						mark_need, mark_done,
						t_course.mark_mode, task_prog 
					FROM 
						t_resitplan a 
						INNER JOIN t_course ON t_course.cid = a.cid 
					WHERE 
						a.task_id = :taskId";
						
			queryObj = new query( datasource=application.dnsSlave );
			
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			
			rs_task = queryObj.execute( sql=sql ).getResult();


			progress = 0;
			
			if ( rs_task.mark_need ) {
					progress = int( rs_task.mark_done * 10000 / rs_task.mark_need ) / 100;
			}
			

			/* 生成分页 */
			pageAdvice.setTotleRow( rs_task.mark_need );
			pageAdvice.setStartRow( event.getArg("Start", 1) );
			pageAdvice.setPage( event.getArg("Page", 1) );
			
			pageAdvice.setRowPerPage( 30 );
			
			pageArray = pageAdvice.getPageList();

			if ( rs_task.mark_mode eq "2" and ( rs_task.task_prog eq "0" or rs_task.task_prog eq "1" or rs_task.task_prog eq "2" or rs_task.task_prog eq "4" ) ) {
				
				checked = true;
				
				/* 更新成绩提交状态 */
				transaction {
					
					sql = "UPDATE 
								t_resitplan 
							SET 
								task_prog = '1' 
							WHERE 
								task_id = :taskId ";
								
					queryObj = new query( datasource=application.dnsMaster );
					
					queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
				/* 传递参数处理 */
				pageArgs = structNew();
				structInsert( pageArgs, "TSK", taskId, true );
				structInsert( pageArgs, "TT", taskType, true );
				structInsert( pageArgs, "Sign", encrypt(taskId, teacherId, "PBEWithMD5AndDES", "Hex"), true );
				
				
				
				transaction {

					/* 第三步 更新成绩提交数量 */
					
					sql = "SELECT
								count(*) markNeed,
								sum
								(
									CASE 
									WHEN 
										mark_renote = '1' and (mark_resit > 0 or mark_resit = 0)
										THEN 1 
									WHEN 
										mark_renote > '1' OR mark_renote < '1' 
										THEN 1 
									ELSE 0
									END
								) markDone 
							FROM 
								t_temp_mark_resit t 
							WHERE 
								t.task_id = :taskId ";
								
					queryObj = new query( datasource=application.dnsMaster );
					
					queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
					
					rs_check = queryObj.execute( sql=sql ).getResult();
					

					sql = "UPDATE 
								t_resitplan 
							SET 
								mark_need = :markNeed,
								mark_done = :markDone 
							WHERE 
								task_id = :taskId ";
								
					queryObj = new query( datasource=application.dnsMaster );
					
					queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="markNeed", value=rs_check.markNeed, cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="markDone", value=rs_check.markDone, cfsqltype="cf_sql_integer" );
					
					queryObj.execute( sql=sql );
					
				}
				

				/* 载入成绩提交名单 */
				
				sql = "SELECT 
							a.scc_id,
							t_student.stu_id, t_student.stu_name,
							t_class.cls_name, t_subject.sbj_short,
							a.mark_resit, a.mark_renote 
						FROM
							t_temp_mark_resit a 
							INNER JOIN t_student ON t_student.stu_id = a.stu_id 
							INNER JOIN t_class ON t_class.cls_id = t_student.cls_id 
							INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id 
						WHERE 
							a.task_id = :taskId 
						ORDER BY 
							a.stu_id ";
							
				queryObj = new query( datasource=application.dnsSlave );
				
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				
				rs_student = queryObj.execute( sql=sql ).getResult();
				
				
				startRow = pageAdvice.getStartRow();
				endRow = startRow + pageAdvice.getRowPerPage() - 1;
			}
			
			
		}

		/* 判断当前显示课表内容 */
		currentTab = event.getArg("TabID", "labSheet");
		
	</cfscript>
</cfsilent>

<!---<div id="out"></div>--->
<cfif checked >

		<div class="UItab">
			<div class="tabLables">
				<span <cfif currentTab eq "labSheet">class="active"</cfif> id="labSheet" tabTarget="Sheet">网上成绩提交</span>
			</div>
		</div>
		<script language="javascript" type="text/javascript">
			//<![CDATA[
			<!--
			$(document).ready(function() {
						
				/* init Tab */
				$("div.tabContent").hide();
				$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
				
				$("div.tabLables > span").click(function(){
					var $targetID = $(this).attr("tabTarget");
						
					$("div.tabLables span").removeClass("active");
					$(this).addClass("active");
							
					$("div.tabContent").not('[id="' + $targetID + '"]').hide();
					$("div.tabContent#" + $targetID).show();
				});
						
			});
			// -->
			//]]>
		</script>

		<div id="Sheet" class="tabContent">
			
			<div class="noticeBlock">
				<h3>课程补考成绩</h3>
				<p>
					<span class="img icon16x16 message"></span>
					请注意, 这里需要提交的是课程补考成绩. 当前课程成绩按照二级制提交, 课程考核结果选择为 通过/不通过. 
				</p>
				<hr/>
			</div>
			
			<div class="UIProgressbar">
				<span class="progressBar" id="pb1">0%</span>
				<!---<p id="output">成绩提交进度</p>--->
			</div>
			
			<script language="javascript" type="text/javascript">
				//<![CDATA[
				<!--
				$(document).ready(function() {
					/* init Progress */
					$("#pb1").progressBar(
											<cfoutput>#progress#</cfoutput>,
											{
												boxImage : '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbar.gif',
												barImage : {
													0:  '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_red.gif',
													30: '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_orange.gif',
													70: '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_green.gif'
													}
												});
				});
				// -->
				//]]>
			</script>
			
			<!--- 如果计分完成, 则显示跳转到成绩检查页面 --->
			<div id="complateNotice" class="systemNotice <cfif progress lt 100 or event.isArgDefined("Target")>hidden_elem</cfif>">
				<h3><span class="img icon16x16 info"></span>成绩已完成录入</h3>
				<form id="formRemove" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('taskMarkResitWizardChecker2')#</cfoutput>">
					<input type="hidden" name="TSK" value="<cfoutput>#taskId#</cfoutput>" />
					<input type="hidden" name="TT" value="<cfoutput>#taskType#</cfoutput>" />
					<input type="hidden" name="Sign" value="<cfoutput>#encrypt(taskId, teacherId, 'PBEWithMD5AndDES', 'Hex')#</cfoutput>" />
					<div class="lable"><input class="button2" type="submit" value="检查已录入成绩" /></div>
				</form>
			</div>
			
			<table class="UIEditable">
				<thead>
					<tr>
						<td width="30"></td>
						<td>学号</td>
						<td>姓名</td>
						<td>班级</td>
						<td>专业</td>
						<td width="140">成绩</td>
						<td width="120">备注</td>
						<td width="25"></td>
					</tr>
				</thead>
				<tbody>
					<cfset row = pageAdvice.getOffset() />
                    <cfloop startrow="#startRow#" endrow="#endRow#" query="rs_student">
						<cfset row++ />
						<cfset codeSign = encrypt(rs_student.scc_id, teacherId, "PBEWithMD5AndDES", "Hex") />
						<tr class="editRows studyType<cfoutput>#rs_student.mark_resit#</cfoutput> <cfif event.getArg('Target') eq rs_student.scc_id>lastEdited</cfif>">
							<td class="index"><cfoutput>#row#</cfoutput></td>
							<td><span class="numeric"><cfoutput>#rs_student.stu_id#</cfoutput></span></td>
							<td><cfoutput>#rs_student.stu_name#</cfoutput></td>
							<td><cfoutput>#rs_student.cls_name#</cfoutput></td>
							<td><cfoutput>#rs_student.sbj_short#</cfoutput></td>
							<td>
								<input onClick="changeScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '1', '<cfoutput>#codeSign#</cfoutput>');" type="radio" name="MarkNote<cfoutput>#rs_student.scc_id#</cfoutput>" value="60" <cfif rs_student.mark_renote eq "1" and rs_student.mark_resit gte 60>checked="checked"</cfif>/>合格 &nbsp;&nbsp;
								<input onClick="changeScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '1', '<cfoutput>#codeSign#</cfoutput>');" type="radio" name="MarkNote<cfoutput>#rs_student.scc_id#</cfoutput>" value="0" <cfif rs_student.mark_renote eq "1" and rs_student.mark_resit lt 60 and rs_student.mark_resit gte 0>checked="checked"</cfif>/>不合格
							</td>
							<td>
								<input onClick="changeScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '2', '<cfoutput>#codeSign#</cfoutput>');" type="radio" name="MarkNote<cfoutput>#rs_student.scc_id#</cfoutput>" value="-1" <cfif rs_student.mark_renote eq "2">checked="checked"</cfif>/>缺考 &nbsp;&nbsp;
							</td>
							<td><span name="MarkStat<cfoutput>#rs_student.scc_id#</cfoutput>" class="stat <cfif rs_student.mark_resit gte 0 or rs_student.mark_renote neq "1">checked<cfelse>todo</cfif>"></span></td>
						</tr>
					</cfloop>
				</tbody>
			</table>
			
			<script language="javascript" type="text/javascript">
				//<![CDATA[
				<!--
				
				function refreshTask() {
					
					$.post(
							"<cfoutput>#buildURL('apiTaskMarkResitFlush')#</cfoutput>", 
							{
								"TSK": '<cfoutput>#taskId#</cfoutput>',
								"Sign": '<cfoutput>#encrypt(taskId, teacherId, "PBEWithMD5AndDES", "Hex")#</cfoutput>', 
								"seed": (new Date()).getTime()
							},
							function(data) {
								
								var result = $.parseJSON(data);
											
								if ( result.success ) {
									
									$("#pb1").progressBar(
															result.Progress, 
															{
																boxImage : '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbar.gif',
																barImage : {
																	0:  '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_red.gif',
																	30: '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_orange.gif',
																	70: '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_green.gif'
																	}
															});
								
									if ( result.Progress == 100 ) {
										$("#complateNotice").removeClass("hidden_elem");
									}
									
								}
								
							});
					
				}
				
				function changeScroll( chooserId, markNote, sign ) {
					
					var $mark =$("input:checked[name='MarkNote" + chooserId + "']");
					var $stat = $("span[name='MarkStat" + chooserId + "']");
					
					var mark = $mark.val();
					
					switch(markNote) {
						
						case "1":
							/* 检查分数 */

							$stat.removeClass("delete").removeClass("todo").removeClass("checked").addClass("waiting");
								
							$.post(
									"<cfoutput>#buildURL('apiStudentMarkResitSave')#</cfoutput>", 
									{
										"ChooseID": chooserId, 
										"MarkMode": "2", 
										"Mark": mark, 
										"MarkNote": "1", 
										"Sign": sign, 
										"seed": (new Date()).getTime()
									},
									function(data) {

										var result = $.parseJSON(data);
											
										if ( result.success ) {
											
											$mark.val( result.Mark );
												
											$stat.removeClass("waiting").addClass("checked");
												
											/* 刷新进度 */
											refreshTask();
										}
										else {
											//alert( result.reason );
											$stat.removeClass("waiting").addClass("delete");
										}
										
									});

							break;
						
						case "2":
						case "9":
							
							$stat.removeClass("delete").removeClass("todo").removeClass("checked").addClass("waiting");
							
							$.post(
									"<cfoutput>#buildURL('apiStudentMarkResitSave')#</cfoutput>", 
									{
										"ChooseID": chooserId, 
										"MarkMode": "2", 
										"Mark": "-1", 
										"MarkNote": markNote, 
										"Sign": sign, 
										"seed": (new Date()).getTime()
									},
									function(data) {
										
										//$("#out").html(data);
										var result = $.parseJSON(data);
											
										if ( result.success ) {
											
											$stat.removeClass("waiting").addClass("checked");
											
											/* 刷新进度 */
											refreshTask();
										}
										else {
											//alert( result.reason );
											$stat.removeClass("waiting").addClass("delete");
										}
										
									});
							
							break;
						
					}


				}
				
				// -->
				//]]>
			</script>

			<div class="pagination">
				<div class="summary">Page:<cfoutput>#pageAdvice.getPage()#</cfoutput>/<cfoutput>#pageAdvice.getPageCount()#</cfoutput> Totle:<cfoutput>#pageAdvice.getTotleRow()#</cfoutput></div>
				<div class="lists">
					<cfloop from="1" to="#arrayLen(pageArray)#" index="page">

						<cfset structInsert( pageArgs, "Start", pageArray[page][2], true ) />
						<cfset structInsert( pageArgs, "Page", pageArray[page][3], true ) />

						<cfswitch expression="#pageArray[page][1]#">
							<cfcase value="D">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>"><cfoutput>#pageArray[page][3]#</cfoutput></a>
							</cfcase>
							<cfcase value="C">
								<span><cfoutput>#pageArray[page][3]#</cfoutput></span>
							</cfcase>
							<cfcase value="F">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">First</a>
							</cfcase>
							<cfcase value="P">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Previous</a>
							</cfcase>
							<cfcase value="N">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Next</a>
							</cfcase>
							<cfcase value="L">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Last</a>
							</cfcase>
						</cfswitch>
					</cfloop>
				</div>
			</div>
			
		</div>
		
	
	<cfelse>
	
		<div class="systemNotice">
			<h3><span class="img icon16x16 message"></span>错误的参数</h3>
			<p>请关闭浏览器重新登录 或 检查您是否使用了正确访问方式</p>
		</div>
</cfif>